<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <iframe id="iframe" src="http://localhost:3000/b.html" frameborder="0"></iframe>
  <script>
    // 添加cookie测试一下
    document.cookie = 'name=zhangsan';

    const url = 'http://localhost:3000/b.html';
    const cookie = document.cookie;
    if (cookie) {
        // key: name   value: zhangsan
        const [key, value] = cookie.split(';')[0].split('=');
        const iframe = document.querySelector('#iframe');
        iframe.contentWindow.document.cookie = document.cookie;
    }
  </script>
</body>
</html>